import { ElLoading } from 'element-plus'

// 加载中
let loading; let loadingCount = 0
function startLoading(title) {
  loading = ElLoading.service({
    fullscreen: true,
    lock: true,
    text: title?title:'加载中......',
    background: 'rgba(0, 0, 0, .2)'
  })
}

const endLoading = () => {
  loading.close()
}

export const showLoading = (title) => {
  if (loadingCount === 0) startLoading(title)
  loadingCount++
}

export const hideLoading = () => {
  if (loadingCount <= 0) return
  loadingCount--
  if (loadingCount === 0) {
    setTimeout(() => {
      endLoading()
    }, 100)
  }
}
